﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using RRRSRoguelikeData;


namespace RRRSRoguelike.Entities
{
	/// <summary>
	/// Describes the dungeon object.
	/// </summary>
	class Dungeon
	{
		public DungeonData Data;
		public List<DungeonLevel> Levels;

		public Dungeon()
		{
			Levels = new List<DungeonLevel>();
		}

		public void LoadData(string fileName)
		{
			Data = Files.ReadDataFromXML(Path.Combine(Properties.Settings.Default.CustomFolder, fileName));
		}

		public static Point AddPoints(Point A, Point B)
		{
			return new Point(A.X + B.X, A.Y + B.Y);
		}

		/// <summary>
		/// Gets the vector between two points
		/// </summary>
		/// <param name="A"></param>
		/// <param name="B"></param>
		/// <returns></returns>
		public static Point GetDistanceVector(Point A, Point B)
		{
			return new Point(B.X - A.X, B.Y - A.Y);
		}

		/// <summary>
		/// always returns positive
		/// </summary>
		/// <param name="A"></param>
		/// <param name="B"></param>
		/// <returns></returns>
		public static int GetDistance(Point A, Point B)
		{
			var result = GetDistanceVector(A, B);

			return (Math.Abs(result.X) + Math.Abs(result.Y));
		}

		public void SetupLayers()
		{
			var i = 1;
			foreach (var s in Data.Levels)
			{
				if (s == "Random")
				{
					Levels.Add(new DungeonLevel(i, Constants.DungeonWidth, Constants.DungeonHeight));
				}
				i++;
			}
		}

	}
}
